{extend name="public/base" /}
{block name="content"}
<form class="layui-form layui-form-pane form-search" action="{:url()}" onsubmit="return false" method="post" autocomplete="off">
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">站内信标题</label>
        <label class="layui-input-inline">
            <input name="title" value="" placeholder="" class="layui-input">
        </label>
    </div>
    <div class="layui-form-item layui-inline">
        <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i>搜索</button>
    </div>
</form>
<table id="letterTable"  data-url="{:url('index')}" data-target-search="form.form-search"></table>
{/block}
{block name='script'}
<script>
    $(function () {
        $('#letterTable').layTable({
            even: true,
            height: 'full',
            method: 'post',
            sort: {field: 'id', type: 'desc'},
            url: "{:url('index')}" ,
            page: true,
            cols: [[
                {field: 'id', title: 'id', width: 100, align: 'center'},
                {field: 'member_id', title: '会员id', width: 100, align: 'center'},
                {field: 'title', title: '标题', minWidth: 100, align: 'center'},
                {field: 'status', title: '状态', align: 'center', minWidth: 210, templet: function (d){
                        return d.status==1 ? "已读":"未读"
                    }},
                {field: 'update_at', title: '修改时间', align: 'center', sort: true},
                {field: 'create_at', title: '创建时间', align: 'center', sort: true},
                {field: 'create_operator', title: '创建人账户', align: 'center', minWidth: 170, sort: true},
                {field: 'update_operator', title: '更新人账户', align: 'center', minWidth: 170, sort: true},
                {toolbar: '#toolbar', title: '操作面板', align: 'center',  fixed: 'right'}
            ]]
        });
        $.menu.highlight_subnav("{:url('index')}")
    });
    function del(id) {
        var index =  $.msg.confirm("确认删除吗？",function (){
            $.post("{:url('del')}",{id:id},function (res){
                if (res.code >1) $.msg.error(res.msg, 3, function () {
                    $('#letterTable').trigger('reload');
                }); else {
                    $.msg.success(res.msg,3,function (){
                        $('#letterTable').trigger('reload');
                    })
                }
            },'json')
        },function (){
            layer.close(index);
        })
    }
</script>
<script type="text/html" id="toolbar">
    {{-d.is_del!=0 ? '已经删除' : ''}}
    <a class="layui-btn layui-btn-sm" data-modal='{:url("edit")}?id={{d.id}}'  {{-d.is_del!=0 ? 'style="display:none;"' : ''}} >编 辑</a>
    <a class="layui-btn layui-btn-sm layui-btn-danger"    {{-d.is_del!=0 ? 'style="display:none;"' : ''}}  onclick="del('{{d.id}}')" >删除</a>
</script>
{/block}
